#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=2e5+5,M=1e6+5;
ll t,n,a[N],b[M],ans,i,j=1;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        ans=0;
        cin>>n;
        for(i=1;i<=n;i++)
            cin>>a[i];
        sort(a+1,a+n+1);
        for(i=1;i<=n;i++){
            if(a[i]==a[i-1])
                b[j]++;
            else
                b[++j]++;
            if(b[j]>=2)
                ans+=a[i];
        }
        cout<<ans<<endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
